<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>智慧巴士更新</title>
    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../js/jquery.cookie.js"></script>
    <script src="../../js/layer/layer.js"></script>
    <style type="text/css">
        ul li {
            list-style: none;
            display: inline-block;
        }
    </style>
</head>
<body>
<div>
    <ul>
        <li>编号:<input type="text" readonly="readonly" id="id" name="id"/></li>
        <li>巴士名称:<input type="text" id="name" name="name"/></li>
        <li>巴士起点:<input type="text" id="startPoint" name="startPoint"/></li>
        <li>巴士终点:<input type="text" id="endPoint" name="endPoint"/></li>
        <li>价格:<input type="text" id="price" name="price"/></li>
        <li>开行时间:<input type="text" id="time" name="time"/></li>
        <li><input type="button" value="提交" id="btn"/></li>
    </ul>
</div>
</body>
<script>
    $(function () {
        $("#btn").click(function () {
            submit();
        });
        init();
    });

    function init() {
        var id = getUrlParam("id");
        $.ajax({
            contentType: "json",
            url: baseUrl+"bus/getOneById.json",
            data: {
                id:id
            },
            success: function (data) {
                if (data.code == "200") {
                    $("#id").val(data.bus.id);
                    $("#startPoint").val(data.bus.startPoint);
                    $("#endPoint").val(data.bus.endPoint);
                    $("#price").val(data.bus.price);
                    $("#time").val(data.bus.time);
                } else {
                    layer.msg("获取失败!",{icon:5});
                }
            }
        });
    }


    function submit() {
        var clazz = {
            id: $("#id").val(),
            name:$("#name").val(),
            address:$("#address").val(),
            phone:$("#phone").val()
        }
        $.ajax({
            type: "post",
            dataType:"json",
            contentType: "application/json",
            url: baseUrl+"service/update.json",
            data: JSON.stringify(clazz),
            success: function (data) {
                if (data.code == "200") {
                    window.location.href = baseUrl+"/back/bus/list.html";
                } else {
                    layer.msg("修改失败!",{icon:5});
                }
            }
        });
    }

</script>
</html>